package com.yukefms.rule.formula;

import com.yukefms.common.ListTools;
import com.yukefms.engine.running.MatchedStatus;
import com.yukefms.engine.running.RunningContext;
import com.yukefms.jointpoint.BodyPointCloud;
import com.yukefms.rule.formula.interfaces.AbstractStaticBAFormula;
import com.yukefms.rule.formula.interfaces.DynamicBAFormula;
import com.yukefms.rule.formula.interfaces.StageBAFormula;
import com.yukefms.rule.formula.interfaces.StaticBAFormula;

/**
 * @Description
 * @Author Ping
 * @Date 2021/8/20 10:52
 **/
public class SimpleStageBAFormula extends AbstractStaticBAFormula implements StageBAFormula {

    private DynamicBAFormula dynamic ;
    private StaticBAFormula response ;

    public SimpleStageBAFormula(DynamicBAFormula dynamic, StaticBAFormula response) {
        super() ;
        this.dynamic = dynamic;
        this.response = response;
        ListTools.addAllNoDumplicate(this.jointTypes, this.dynamic.relatedJointTypes());
        ListTools.addAllNoDumplicate(this.jointTypes, this.response.relatedJointTypes());
    }

    @Override
    public boolean hasNextStage() {
        return false;
    }

    @Override
    public StageBAFormula nextStage() {
        return null;
    }

    @Override
    public StageBAFormula currentStage() {
        return this;
    }

    @Override
    public StageBAFormula add(StageBAFormula stage) {
        // In default, seqStageFormula was created for simpleStageFormula.
        StageBAFormula seqStage = new SeqStageBAFormula();
        seqStage.add(this) ;
        seqStage.add(stage) ;
        return seqStage;
    }

    @Override
    public DynamicBAFormula dynamic() {
        return this.dynamic;
    }

    @Override
    public StaticBAFormula response() {
        return this.response;
    }
    @Override
    public MatchedStatus matched(BodyPointCloud bodyPointCloud, RunningContext context) {
        // note that, the response part in the stage was considered.
        return this.response.matched(bodyPointCloud, context) ;
    }

    /**
     *NOTE that, the following two formula was not necessary for StageBAFormula.
     */
    @Override
    public void setSuccessor(StaticBAFormula formula) {

    }

    @Override
    public StaticBAFormula getSuccessor() {
        return null;
    }
}
